import React from 'react';
import { useSelector } from 'react-redux';
import { Navigate } from 'react-router-dom';
import { RootState } from '@/store/rootReducer';

export const withAdminAuth = (WrappedComponent: React.ComponentType) => {
  return function WithAdminAuthComponent(props: any) {
    const loginUser = useSelector((state: RootState) => state.loginUser);

    if (!loginUser || loginUser.userRole !== 'admin') {
      return <Navigate to="/" replace />;
    }

    return <WrappedComponent {...props} />;
  };
}; 